/*
 * DarcyPoreMaterial.C
 *
 *  Created on: 2017年7月27日
 *      Author: liuxiao
 */
#include "../../include/materials/PyrolysisGasPropertyMaterial.h"

#include<iostream>
#include "libmesh/quadrature.h"
using std::cout;
using std::endl;

registerMooseObject("TrilobitaApp", PyrolysisGasPropertyMaterial);

template<>
InputParameters validParams<PyrolysisGasPropertyMaterial>()
{
	InputParameters params = validParams<Material>();

	params.addRequiredParam<std::vector<Real> >("cpg_list", "The vector of pyrolysis gas specific heat values for building the piecewise function");
	params.addRequiredParam<std::vector<Real> >("cpgT_list", "The vector of temperature values for building the piecewise function to compute pyrolysis gas specific heat");
	params.addRequiredParam<std::vector<Real> >("viscosity_list", "The vector of pyrolysis gas viscosity values for building the piecewise function");
	params.addRequiredParam<std::vector<Real> >("viscosityT_list", "The vector of temperature values for building the piecewise function to compute pyrolysis gas viscosity");
	params.addRequiredParam<std::vector<Real> >("hg_list", "The vector of pyrolysis gas enthalpy values for building the piecewise function");
	params.addRequiredParam<std::vector<Real> >("hgT_list", "The vector of temperature values for building the piecewise function to compute pyrolysis gas enthalpy");
	params.addRequiredCoupledVar("temperature", "Coupled Temperature");
	params.addRequiredCoupledVar("pressure", "Coupled Pressure");
  return params;
}

PyrolysisGasPropertyMaterial::PyrolysisGasPropertyMaterial(const InputParameters & parameters) :
    Material(parameters),
	_porosity(getMaterialProperty<Real>("porosity")),
	_permeability(getMaterialProperty<Real>("permeability")),
	_R(getMaterialProperty<Real>("gas_constant")),
	_rhog(declareProperty<Real>("rhog")),
	_mg_x(declareProperty<Real>("mg_x")),
	_mg_y(declareProperty<Real>("mg_y")),
	_mg_z(declareProperty<Real>("mg_z")),
	_cpg(declareProperty<Real>("cpg")),
	_viscosity(declareProperty<Real>("viscosity")),
	_hg(declareProperty<Real>("hg")),
	_T_value(coupledValue("temperature")),
	_P_value(coupledValue("pressure")),
	_gradient_T_value(coupledGradient("temperature")),
	_gradient_P_value(coupledGradient("pressure"))
{
	_cpg_list = getParam<std::vector<Real>>("cpg_list");
	_cpgT_list = getParam<std::vector<Real>>("cpgT_list");
	_func_cpg_T = LinearInterpolation(_cpgT_list,_cpg_list);
	_viscosity_list = getParam<std::vector<Real>>("viscosity_list");
	_viscosityT_list = getParam<std::vector<Real>>("viscosityT_list");
	_func_viscosity_T = LinearInterpolation(_viscosityT_list,_viscosity_list);
	_hg_list = getParam<std::vector<Real>>("hg_list");
	_hgT_list = getParam<std::vector<Real>>("hgT_list");
	_func_hg_T = LinearInterpolation(_hgT_list,_hg_list);

}

void PyrolysisGasPropertyMaterial::initQpStatefulProperties()
{
	  _rhog[_qp] = _P_value[_qp]/_R[_qp]/(_T_value[_qp]+1e-10);
	  _mg_x[_qp]=  -_rhog[_qp]*_permeability[_qp]/(_viscosity[_qp])*_gradient_P_value[_qp](0);
	  _mg_y[_qp] = -_rhog[_qp]*_permeability[_qp]/(_viscosity[_qp])*_gradient_P_value[_qp](1);
	  _mg_z[_qp] = -_rhog[_qp]*_permeability[_qp]/(_viscosity[_qp])*_gradient_P_value[_qp](2);
	  _cpg[_qp] = _func_cpg_T.sample(_T_value[_qp]);
	  _viscosity[_qp] = _func_viscosity_T.sample(_T_value[_qp]);
	  _hg[_qp] = _func_hg_T.sample(_T_value[_qp]);
}
void PyrolysisGasPropertyMaterial::computeQpProperties()
{
	_rhog[_qp] = _P_value[_qp] / _R[_qp] / (_T_value[_qp] + 1e-10);
	_mg_x[_qp] = -_rhog[_qp] * _permeability[_qp] / (_viscosity[_qp]) * _gradient_P_value[_qp](0);
	_mg_y[_qp] = -_rhog[_qp] * _permeability[_qp] / (_viscosity[_qp]) * _gradient_P_value[_qp](1);
	_mg_z[_qp] = -_rhog[_qp] * _permeability[_qp] / (_viscosity[_qp]) * _gradient_P_value[_qp](2);
	_cpg[_qp] = _func_cpg_T.sample(_T_value[_qp]);
	_viscosity[_qp] = _func_viscosity_T.sample(_T_value[_qp]);
	_hg[_qp] = _func_hg_T.sample(_T_value[_qp]);
}




